<?php
    //引入init配置文件
    require "init.php";
    //接受商品id和购买数量
    $goods_id = $_GET['goods_id'];
    $qty = $_GET['qty'];

    //查询商品的一些信息通过商品id
    $sql = "
            select
            i.iname,g.gname,g.price,g.msg,g.zan,g.stock,g.sale,g.id
            from
            ".PRE."goods as g,".PRE."image as i
            where
            g.id = i.goods_id  and g.state = 1 and i.cover = 1 and g.id='$goods_id'  limit 1
            ";
    $goods_info = getRow($link, $sql);

    //查询用户的收货地址
    //现获取用户id
    $user_id= $_SESSION['home']['id'];
    $sql = "select id,address,default_a from ". PRE . "user_address where user_id = '$user_id'";

    $address_list = query($link, $sql);
//    echo "<pre>";
//    print_r($address_list);die;





?>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <link rel="icon" href="./public/home/imgs/logo.jpg">
    <title>小米手机专卖店(ximiao)</title>

    <!-- Bootstrap -->
    <link href="./public/home/css/bootstrap.min.css" rel="stylesheet">
    <link href="./public/home/css/index.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="./public/home/js/html5shiv.min.js"></script>
    <script src="./public/home/js/respond.min.js"></script>
    <![endif]-->
</head>
<body>
    <!--引入导航条-->
    <?php require ROOT_PATH."./com/nav.php" ?>


    <!--立即购买页开始-->
    <form action="<?php echo ROOT_URL?>pay.php" method="post">
        <div class="container mt50">
            <div class="row mt20">
                <h3><b>确认收货地址</b></h3>
                <?php if(empty($address_list)):?>
                    <a href="./add_address.php"><span class="btn btn-primary">新建地址</span></a>
                <?php else:?>
                    <?php foreach($address_list as $value):?>
                        <?php if($value['default_a'] == 1):?>
                            <div class="radio col-md-12">
                                <label>
                                    <input type="radio" name="adress" id="adress" value="<?php echo $value['id']?>" checked><?php echo $value['address']?>
                                </label>
                            </div>
                            <?php continue;?>
                        <?php endif;?>
                        <div class="radio col-md-12">
                            <label>
                                <input type="radio" name="adress" id="adress" value="<?php echo $value['id']?>"><?php echo $value['address']?>&nbsp;&nbsp;&nbsp;&nbsp;<a href="./com/buydo.php?act=set_default_address&id=<?php echo $value['id']?>">设为默认地址</a>
                            </label>
                        </div>
                    <?php endforeach;?>
                    <br>
                    <a href="./add_address.php"><span class="btn btn-primary">新增地址</span></a>
                <?php endif;?>


            </div>

        </div>
        <div class="container mt30">
            <div class="row">
                <h3><b>确认订单信息</b></h3>
            </div>
            <div class="row col-md-12 mt30">

                    <table class="row col-md-12 text-center  table" cellpadding="0" cellspacing="0">
                        <tr>
                            <th class="text-center">商品图片</th>
                            <th class="text-center">商品名称</th>
                            <th class="text-center">商品价格</th>
                            <th class="text-center">商品数量</th>
                            <th class="text-center">小计</th>
                        </tr>
                        <?php if(!empty($goods_info)):?>
                            <input type="hidden" name="0" value="<?php echo $goods_info['id']?>">
                            <input type="hidden" name="price<?php echo $goods_info['id']?>" value="<?php echo $goods_info['price']?>">
                            <tr>
                                <!--商品图片-->
                                <td class="col-md-2">
                                    <a href="<?php echo ROOT_URL?>goods_details.php?id=<?php echo $goods_info['id']?>">
                                        <img src="<?php echo get_img_url(ROOT_URL . 'upload/',$goods_info['iname'],50)?>">
                                    </a>
                                </td>
                                <!--商品名称-->
                                <td class="col-md-2">
                                    <a href="<?php echo ROOT_URL?>goods_details.php?id=<?php echo $goods_info['id']?>">
                                        <?php echo $goods_info['gname']?>
                                    </a>
                                </td>
                                <!--商品价格-->
                                <td class="col-md-2"><h4 id="price<?php echo $goods_info['id']?>"><?php echo $goods_info['price']?><h4></td>
                                <!--商品数量-->
                                <td class="col-md-2">
                                    <span class="price">
                                        <div class="col-md-3  btn btn-default" onclick="minus(<?php echo $goods_info['id']?>)">▬</div>
                                        <div class="col-md-6">
                                            <input type="number" name="qty<?php echo $goods_info['id']?>" value="<?php echo $qty;?>" id="number<?php echo $goods_info['id']?>"
                                                   class="form-control text-center"
                                                   onchange="change_num(<?php echo $goods_info['id']?>)">
                                        </div>
                                        <div class="col-md-3 btn btn-default" onclick="plus(<?php echo $goods_info['id']?>)">✚</div>
                                    </span>
                                </td>
                                <!--商品小计-->
                                <td class="col-md-2"><h4 id="total<?php echo $goods_info['id']?>"><?php echo $goods_info['price'] * $qty?></h4></td>
                            </tr>
                            <tr>
                                <td colspan="6" class="text-right">
                                    <button class="btn btn-danger" type="submit">提交订单</button>
                                </td>
                            </tr>
                        <?php endif;?>
                    </table>

            </div>

        </div>
    </form>
    <!--立即购买页结束-->


    <!--引入底部开始-->
    <?php require ROOT_PATH."./com/footer.php" ?>

<script src="./public/home/js/index.js"></script>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="./public/home/js/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="./public/home/js/bootstrap.min.js"></script>
</body>
</html>